<template>
	<div class="btn-group">
		<button @click="edit" class="btn btn-white btn-xs btn-info btn-round">
			编辑
		</button>&nbsp;		
		<button @click="del" class="btn btn-white btn-xs btn-warning btn-round">
			删除
		</button>
	</div>
</template>

<script>
	export default {
		name: 'operation',
		props: {
			category: Object
		},
		methods: {
			edit() {
				this.$parent.category = $.extend({}, this.category)
				$('#save-modal').modal('show')
			},
			del() {
				this.$confirm({
						title: ' ',
						content: '确定删除分类: ' + this.category.name + '?'
					})
					.then(() => {
						let url = process.env.VUE_APP_SERVER + 'business/admin/category/delete/' + this.category.id
						this.$axios.delete(url)
							.then(res => {
								if (res.data.status === 1) {
									this.$toast('已删除分类:' + this.category.name, this.$global.toast.success)
									if(this.category.parentId === 0) this.$parent.activeCategory = {}
									this.$parent.all()
								} else {
									this.$toast(res.data.msg, this.$global.toast.fail)
								}
							})						
						// this.$emit('del', this.category)
					})
					.catch(() => {})
			}
		}
	}
</script>

<style>
</style>
